package com.csust.automaticteach.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csust.automaticteach.model.dto.chathistory.ChatHistoryQueryRequest;
import com.csust.automaticteach.model.entity.ChatHistory;
import com.baomidou.mybatisplus.extension.service.IService;
import com.csust.automaticteach.model.entity.User;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;

import java.time.LocalDateTime;

/**
* @author 钰玟
* @ description 针对表【t_chat_history(对话历史)】的数据库操作Service
* @ createDate 2025-09-27 13:36:20
*/
public interface ChatHistoryService extends IService<ChatHistory> {
    /**
     * 添加对话消息
     * @param bizId 业务ID
     * @param bizType 业务类型
     * @param message 消息
     * @param messageType 消息类型
     * @param userId 用户ID
     * @return 添加结果
     */
    boolean addChatMessage(Long bizId, Integer bizType, String message, String messageType, Long userId);

    boolean deleteChatMessage(Long bizId, Integer bizType);

    QueryWrapper<ChatHistory> getQueryWrapper(ChatHistoryQueryRequest chatHistoryQueryRequest);

    Page<ChatHistory> listAppChatHistoryByPage(Long bizId, Integer bizType, int pageSize,
                                               LocalDateTime lastCreateTime,
                                               User loginUser);
    /**
     *  加载对话历史到内存
     * @param bizId 业务ID
     * @param bizType 业务类型
     * @param chatMemory 缓存
     * @param maxCount 最大加载数量
     * @return 加载数量
     */
    int loadChatHistoryToMemory(Long bizId, Integer bizType, ChatMemory chatMemory, int maxCount);
}
